<!DOCTYPE html>
<html>
<head>
    <title>模块审核</title>
    <link href="__PLUGIN_TMPL__/public/assets/layui/css/layui.css" rel="stylesheet" type="text/css">
    <link href="__PLUGIN_TMPL__/public/assets/layui/css/backend.min.css" rel="stylesheet" type="text/css">
    <include file='public/head'>
        <style>
            table th, table td{text-align: center;}
            .ml-10 { margin-left: 10px; }
			.layui-icon{font-size: 14px !important;}
			.layui-form-label{ width: auto;}
			.layui-btn.layui-btn-sm .fa{ font-size: 14px !important;}
			.mr4{ margin-right: 4px;}
			.layui-form-item{ margin-bottom: 0px;}
			.row{ margin: 0 !important;}
        </style>
</head>
<body>

	<div class="wrap js-check-wrap" style="padding: 20px 20px 0px 20px;">
	    <ul class="nav nav-tabs">
	        <php> $currentTab = 4 ;</php>
	        <include file="public/nav" />
	    </ul>
	</div>

    <div class="wrap js-check-wrap">
        <form class="well form-inline margin-top-20" action="{:cmf_plugin_url('Appmarket://audit/index')}" method="get" accept-charset="utf-8">
        	<div class="form-group">
        		<label>流程</label>
        		<select id="select-step" name="step" class="form-control">
        			<option value="100" <?php if( $search[ 'step' ] == 100 ) echo 'selected';?> >全部流程</option>
        			<option value="1" <?php if( $search[ 'step' ] == 1 ) echo 'selected';?> >流程一</option>
        			<option value="2" <?php if( $search[ 'step' ] == 2 ) echo 'selected';?> >流程二</option>
        		</select>
        	</div>
			<div class="form-group">
        		<label></label>
        		<button type="submit" name="search" value="search" class="btn btn-success">查询</button>
        	</div>
        </form>
        <table class="table table-bordered table-hover">
            <thead>
                <tr class="theader">
                	<td width="50">序号</td>
                	<td width="150">模块标识</td>
                    <th width="150">模块菜单名称</th>
                    <th width="250">简介</th>
                    <th width="60">价格</th>
                    <th width="60">开发者</th>
                    <th width="60">版本</th>
                    <th width="80">状态</th>
                    <th width="120">操作</th>
                </tr>
            </thead>
            <tbody class="table-body">
            	<volist name="list" id="vo">
	            	<tr>
	            		<td>{++$key}</td>
	            		<td>{$vo.name}</td>
	            		<td>{$vo.title}</td>
	            		<td>{$vo.describe}</td>
	            		<td>
	            			<if condition = "$vo['price'] eq 0">
									免费
								<else>
									￥{$vo.price}
							</if>
	            		</td>
	            		<td>{$vo.author}</td>
	            		<td>{$vo.version}</td>
	            		<td style="color:{$statusColor[$vo['status']]};">
							<span style="color:orange;">
								<if condition="$vo['step'] eq 1" >
										流程1
									<elseif condition="$vo['step'] eq 2">
										流程2
								</if>
							</span>
							{$statusStr[$vo['status']]}
						</td>
						<td>
							
							<if condition="$vo['installed'] eq 0 ">
							
								<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/install') and $vo['step'] eq 2">
									<a href="javascript:;" onclick="install( this , {$vo.id},'{$vo.name}');" class="btn btn-xs btn-primary" >安装</a>
								</if>
							<else>
								<a href="<?php $url = cmf_parse_name($vo['name'],1).'://adminIndex/index'; echo cmf_plugin_url($url); ?>"  class="btn btn-xs btn-success" >管理</a>
					
								<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/uninstall')">
									<a href="javascript:;" onclick="uninstall( this , {$vo.id},'{$vo.name}');" class="btn btn-xs btn-warning" >卸载</a>
								</if>
								
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/particular')">
								<a href="{:cmf_plugin_url('Appmarket://audit/particular')}?id={$vo.id}" target="_blank" class="btn btn-info btn-xs">详情</a>
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/publish/auditResult')">
								<a href="{:cmf_plugin_url('Appmarket://publish/auditResult')}?id={$vo.id}" target="_blank" class="btn btn-xs btn-success" >历史记录</a>
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/pass')">
								<a href="{:cmf_plugin_url('Appmarket://audit/pass')}?id={$vo.id}&step={$vo.step}" class="btn btn-success btn-xs zy-ajax-confirm">通过</a>
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/refuse')">
								<a href="javascript:;" class="btn btn-danger btn-xs refuse-btn" onclick="refuseOperate({$vo.id},{$vo.step});">拒绝</a>
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/clear')">
								<a href="{:cmf_plugin_url('Appmarket://audit/clear')}?name={$vo.name}" class="btn btn-danger btn-xs zy-ajax-confirm" data-msg="清除模块目录下本模块的残余信息，多见于安转失败的残留包 . 确定要进行此操作？"　title="清除模块目录下本模块的残余信息，多见于安装失败的残留包。">清除</a>
							</if>
							<if condition="cmf_auth_check(cmf_get_current_admin_id(),'plugin/appmarket/audit/particular') and $vo['step'] eq 2">
								<a style="display:none;" href="javascript:;" onclick="showDir( {$vo.id} );" class="btn btn-info btn-xs">源码包目录</a>
							</if>
						</td>
	            	</tr>
            	</volist>
            </tbody>
        </table>
        <empty name="list">
    		<tr>暂无数据~</tr>
    	</empty>
    </div>
<include file='public/scripts'>
<script src="__PLUGIN_TMPL__/public/assets/layui/layui.all.js"></script>
<script src="__STATIC__/js/custom/custom.js"></script>
<script>
//拒绝操作
var refuseOperate = function( id , step ){
	//iframe层-父子操作
	layer.open({
		type: 2,
		title:'驳回操作',
		area: ['80%', '80%'],
		fixed: false, //不固定
		maxmin: true,
		btn:['提交' , '取消'],
		content: '{:cmf_plugin_url("Appmarket://audit/refuse")}',
		yes:function( index ){
			let res = window["layui-layer-iframe" + index].callbackdata();
			if( res == false ){
				layer.msg( '请填写完整再提交。' );
				return false;
			}
			let url = '{:cmf_plugin_url("Appmarket://audit/refusePost")}';
			$.post( url , {id:id,step:step,content:res} ,function(data){
				let icon = (data.code==200)?1:5 ;
				layer.msg(data.message, {icon:icon});
				if( icon ==1 ){
					setTimeout(function(){
						window.location.reload();
					},1200);
				}	
			} , 'json' );
		}
	});
}

//模块安装操作
var install = function( _this , id , name ){
	banBtn(_this);
	let url = "{:cmf_plugin_url('Appmarket://audit/install')}?id="+id+"&name="+name;
	$.get( url , function(data){
		//{"code":0,"msg":"插件不存在!","data":"","url":"","wait":3}
		layerMsg( data );
		cancelBan(_this);
	} , 'json');
}
//卸载模块操作
var uninstall = function( _this , id , name ){
	banBtn(_this);
	let url = "{:cmf_plugin_url('Appmarket://audit/unInstall')}?id="+id+"&name="+name;
	$.get( url , function(data){
		//{"code":0,"msg":"插件不存在!","data":"","url":"","wait":3}
		layerMsg( data );
		if(data.code !=0 ){
			$.get("{:cmf_plugin_url('Appmarket://audit/unInstallDeleteFile')}?id="+id,function(data){console.log(data)});
		}
		cancelBan(_this);
	} , 'json');
}

//layer弹窗
var layerMsg = function( data ){
	console.log(data);
	let icon = ( data.code != 0 ) ? 1 : 5;
	layer.msg( data.msg , { icon : icon } );
	if( icon == 1  ) {
		setTimeout( function(){ 
			if( data.url == '' ){
				window.location.reload();
			}else{
				window.location.href = data.url;
			}
		}, 1200 );
	}
}

var showDir = function( id ){
	//iframe层-父子操作
	layer.open({
	  type: 2,
	  title : '安装包目录',
	  area: ['700px', '450px'],
	  btn: ['关闭'],
	  fixed: false, //不固定
	  maxmin: true,
	  content: '{:cmf_plugin_url("Appmarket://audit/checkDir")}?id='+id
	});
}



</script>
</body>
</html>